package com.zengqingfa.designpattern.structure.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zengqingfa
 * @className Composite
 * @description
 * @create 2021/8/29 18:18
 */
public class Composite implements Component {

    private List<Component> list = new ArrayList<>();

    @Override
    public void add(Component component) {
        list.add(component);
    }

    @Override
    public void remove(Component component) {
        list.remove(component);
    }

    @Override
    public Component get(int i) {
        return list.get(i);
    }

    @Override
    public void operation() {
        list.forEach(component -> {
            component.operation();
        });
    }
}